package top.lyc829.zzl_android.ui.profile;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import java.io.IOException;

import okhttp3.Response;
import top.lyc829.zzl_android.logic.bean.FansNumberBean;
import top.lyc829.zzl_android.logic.bean.ResultBean;
import top.lyc829.zzl_android.logic.network.Network;
import top.lyc829.zzl_android.logic.util.HttpUtil;
import top.lyc829.zzl_android.logic.util.Utils;
import top.lyc829.zzl_android.logic.util.gson.JsonUtilNew;
import top.lyc829.zzl_android.ui.profile.user_fans.UserFansViewModel;

public class UserFansNumberViewModel extends ViewModel {

    private MutableLiveData<Integer> FansNumberBeanMutableLivedata;
    public UserFansNumberViewModel()
    {
        this.FansNumberBeanMutableLivedata=new MutableLiveData<>();
    }
    public MutableLiveData<Integer> getFansNumberBeanMutableLivedata(){
        if(FansNumberBeanMutableLivedata==null)
        {
            FansNumberBeanMutableLivedata=new MutableLiveData<>();
        }
        return FansNumberBeanMutableLivedata;
    }

    public void getFansNumberInfo(int user_id)
    {
        Network.getFansNumberInfo(user_id, new HttpUtil.MyCallback() {
            @Override
            public void success(Response res) throws IOException {
                String resultStr = res.body().string();
                ResultBean<Integer> resultBean= JsonUtilNew.fromJsonObject(resultStr,Integer.class);
                if(resultBean.getCode().equals(200))
                {
                    getFansNumberBeanMutableLivedata().postValue(resultBean.getData());
                }
                else
                {
                    failed(new IOException(resultBean.getMsg()));
                }

            }

            @Override
            public void failed(IOException e) {
                Utils.Sout(e.getMessage());
            }
        });
    }

}

